<template>
  <DynamicForm
    v-model="formDataList[index]"
    :form-config.sync="formConfig"
  >

  </DynamicForm>
</template>

<script>
import {FormConfig} from "@localModules/ZhiXinLib/element-components/dynamic-form/ConfigType";
import DynamicForm from "@localModules/ZhiXinLib/element-components/dynamic-form";
import typeOfUtils from "@localModules/ZhiXinLib/utils/type-of-utils";

export default {
  name: "FormItem",
  components: {
    DynamicForm
  },
  props: {
    formDataList: Array,
    index: Number
  },
  data() {
    return {
      formConfig: new FormConfig({
        span: 6
      }, [
        {
          span: 6,
          label: '季度区间选择',
          prop: 'index11',
          type: "datePicker",
          setHidden: (formData, formItem) => {
            if (this.index === 1) {
              return false
            }
            if (typeOfUtils.isNotEmpty(formData.index9)) {
              return true
            }
            return false
          },
          setOpacity: (formData, formItem) => {
            if (this.index === 0) {
              return false
            }
            if (typeOfUtils.isNotEmpty(formData.index9)) {
              return true
            }
            return false
          },
          props: {
            type: 'quarterrange',
            format: 'yyyy年 第Q季度',
            'value-format': 'yyyy年 第Q季度',
          },
          rules: [{required: true, message: '不能为空'}]
        },
        {
          span: 12,
          label: '年区间选择',
          prop: 'index9',
          type: "datePicker",
          props: {
            type: 'yearrange',
            format: 'yyyy',
            'value-format': 'yyyy',
          },
          rules: [{required: true, message: '不能为空'}]
        },
        (formData) => {
          const result = []
          if(formData.index9){
            result.push({
              span: 12,
              label: '函数渲染年区间选择',
              prop: 'indexFunc',
              type: "datePicker",
              props: {
                type: 'yearrange',
                format: 'yyyy',
                'value-format': 'yyyy',
              },
              rules: [{required: true, message: '不能为空'}]
            })
          } else {
            this.$set(formData,'indexFunc',undefined)
          }
          return result
        }
      ])
    }
  }
}
</script>

<style scoped lang="scss">

</style>
